<?php

function writeLog($mes,$file_name='storeCommission_log')
{
    $years = date('Y-m-d');
    //设置路径目录信息
    $url  = '../temp/logs/'.$years.'/'.$years.'_'.$file_name.'.txt';
    //取出目录路径中目录(不包括后面的文件)
    $dir_name = dirname($url);
    //如果目录不存在就创建
    if(!file_exists($dir_name)) {
        $res = mkdir(iconv("UTF-8","GBK",$dir_name),0777,true);
    }
    file_put_contents($url,date('Y-m-d H:i:s').":".$mes."\n",FILE_APPEND);
}



//function get_client_ip() {
//    $ip = $_SERVER['REMOTE_ADDR'];
//    if (isset($_SERVER['HTTP_CLIENT_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CLIENT_IP'])) {
//        $ip = $_SERVER['HTTP_CLIENT_IP'];
//    } elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) {
//        foreach ($matches[0] AS $xip) {
//            if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) {
//                $ip = $xip;
//                break;
//            }
//        }
//    }
//    return $ip;
//}